package com.example.musicplayer.activity;

import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.musicplayer.R;
import com.example.musicplayer.adapter.TabsAdapter;
import com.example.musicplayer.fragment.MusicPlayPage.LyricFragment;
import com.example.musicplayer.fragment.MusicPlayPage.RecommandFragment;
import com.example.musicplayer.fragment.MusicPlayPage.SongFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class PlayMusicActivity extends AppCompatActivity {
    String[] titles = {"推荐", "歌曲", "歌词"};
    List<Fragment> fragments;
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private Toolbar mToolBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_play_page);
        initView();
        initFragment();

        TabsAdapter adapter = new TabsAdapter(getSupportFragmentManager(), fragments, titles);
        mViewPager.setAdapter(adapter);
        mViewPager.setCurrentItem(1);
        mTabLayout.setupWithViewPager(mViewPager);
        setSupportActionBar(mToolBar);
        ActionBar actionBar = getSupportActionBar();
        assert actionBar != null;
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    // 初始化view
    private void initView() {
        mViewPager = findViewById(R.id.music_play_page_viewpager);
        mTabLayout = findViewById(R.id.music_play_page_tablayout);
        mToolBar = findViewById(R.id.music_play_page_toolbar);
    }

    // 初始化Fragment
    private void initFragment() {
        fragments = new ArrayList<>();
        fragments.add(new RecommandFragment());
        fragments.add(new SongFragment());
        fragments.add(new LyricFragment());
    }


}